<!DOCTYPE html>
<html>
<head>
    <title>debug page</title>
    <meta charset='utf-8'>
</head>
<body>
    <script type="module">
        import Pbf from '../index.js';
        import {readTile, writeTile} from './vector_tile.js';

        function read(data) {
            return readTile(new Pbf(data));
        }
        function write(tile) {
            var pbf = new Pbf();
            writeTile(tile, pbf);
            return pbf.finish();
        }

        const data = await (await fetch('../test/fixtures/12665.vector.pbf')).arrayBuffer();

        const tile = read(data);
        const tileJSON = JSON.stringify(tile);

        const N = 100;

        console.time('decode');
        for (let i = 0; i < N; i++) read(data);
        console.timeEnd('decode');

        console.time('encode');
        for (let i = 0; i < N; i++) write(tile);
        console.timeEnd('encode');

        console.time('JSON.parse');
        for (let i = 0; i < N; i++) JSON.parse(tileJSON);
        console.timeEnd('JSON.parse');

        console.time('JSON.stringify');
        for (let i = 0; i < N; i++) JSON.stringify(tile);
        console.timeEnd('JSON.stringify');
    </script>
</body>
</html>
